﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class UserControl_PurchasePlan : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        MultiView1.ActiveViewIndex = Convert.ToInt16(RadioButtonList1.SelectedValue);
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        //SqlQuery query = new Select().From<OrderPrediction4Store>();

        string sqlstr, str1 = "", str2 = "";

        try
        {
            sqlstr = "select * from OrderPrediction4Store where ";
            if (cbIsLowerThanMin.Checked == true)
            {
                str1 += " or Amount < MinStock";
                GridView1.DataSourceID = "";
            }
            if (cbClassA.Checked == true)
            {
                str1 += " or Classification = 'A'";
                GridView1.DataSourceID = "";
            }
            if (cbClassB.Checked == true)
            {
                str1 += " or Classification = 'B'";
                GridView1.DataSourceID = "";
            }
            if (cbClassC.Checked == true)
            {
                str1 += " or Classification = 'C'";
                GridView1.DataSourceID = "";
            }
            if (txtMin.Text != "" && txtMax.Text != "")
            {
                str1 += " or Amount between " + txtMin.Text + " and " + txtMax.Text;
                GridView1.DataSourceID = "";
            }

            if (LastMonth.Text != "")
            {
                str2 += " or LastMonthSale > " + LastMonth.Text;
                GridView1.DataSourceID = "";
            }
            if (Growth.Text != "")
            {
                str2 += " or (Forecast1 - LastMonthSale)/LastMonthSale >" + Convert.ToString(Convert.ToInt32(Growth.Text) / 100);
                GridView1.DataSourceID = "";
            }

            if (str1 != "" && str2 != "")
            {
                sqlstr += "(ISBN = ''" + str1 + ") and (ISBN = ''" + str2 + ")";
            }
            else if (str1 == "" && str2 == "")
            {
                sqlstr += "ISBN != ''";
            }
            else
            {
                sqlstr += "ISBN = ''" + str1 + str2;
            }

            if (GridView1.DataSourceID == "")
            {
                sqlstr += " order by LastMonthSale DESC";

                GridView1.DataSource = FormAccess.GetFilteredSet(sqlstr);
                GridView1.DataBind();
            }
        }
        catch (Exception ex)
        {
            System.Windows.Forms.MessageBox.Show(ex.Message);
            return;
        }
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        //string allocationId, isbn, max, stock, storeId;
        //allocationId = HiddenField1.Value;
        //isbn = GridView1.Rows[GridView1.SelectedIndex].Cells[0].Text;
        //max = GridView1.Rows[GridView1.SelectedIndex].Cells[5].Text;
        //stock = GridView1.Rows[GridView1.SelectedIndex].Cells[3].Text;
        //storeId = DropDownList1.SelectedValue;
        //if (AllocationAccess.CheckStock(allocationId, isbn, storeId, max, stock, cbAmout.Checked))
        //{
        //    GridView2.DataBind();
        //    this.UpdatePanel1.Update();
        //}
        //else
        //{
        //    String scriptString = "<script language=javascript>";
        //    scriptString += "alert('订货量超过库存量,请重新设置！')";
        //    scriptString += "</script>";
        //    ClientScriptManager cs = Page.ClientScript;
        //    //if (!cs.IsStartupScriptRegistered("Startup"))
        //    cs.RegisterClientScriptBlock(Page.GetType(), "", scriptString);
        //}
    }
}
